package test;

import static org.junit.Assert.*;

import java.util.ArrayList;

import main.*;
import movement.Location;

import org.junit.*;

import unit.*;
import dispatch.*;
import emergency.*;

public class useCaseTestDispatchUnits {
	FacadeDispatcher facade;
	Location justALocation;
	
	DispatchCenter center;
	Garage garage;
	Emergency em1,em2,em3,em4;
	
	@Before
	public void setUp() throws Exception {
		String args[] = new String[1];
		args[0] = "environment.dat";
		World world = new World(args);
		facade = new FacadeDispatcher(world);
		
		center = facade.getDispatchCenter();
		garage = center.getGarage();
		justALocation = new Location(10,10,"NameDoesn'tMatter");
		
		em1 = new TrafficAccident(justALocation, Severity.NORMAL, center, 1, 1);
		em2 = new Fire(justALocation, Severity.NORMAL, center, Fire.Size.HOUSE, true, 10, 10);
		em3 = new PublicDisturbance(justALocation, Severity.NORMAL, center, 1);
		em4 = new Robbery(justALocation, Severity.NORMAL, center, false, true);
	}
	
	@Test
	public void testDispatchUnits(){
		// recorded units
		ArrayList <Emergency> recorded = center.getEmergencyboard().getEmergenciesRecorded();
		
		Emergency gonnaBeAssigned = recorded.get(0);
	
		//Suggested units , according to requirements and policy
		ArrayList<Unit> units = gonnaBeAssigned.createSuggestion(gonnaBeAssigned.filterUnits(center.getGarage()));
		
		facade.assignAllUnits(gonnaBeAssigned);
		
		assertEquals(units,gonnaBeAssigned.getUnits());
		
	}
	
	@Test (expected=IllegalArgumentException.class)
	public void testDispatchUnitsNotEnoughUnits(){
		// recorded units
		ArrayList <Emergency> recorded = center.getEmergencyboard().getEmergenciesRecorded();
		
		Emergency gonnaBeAssigned = recorded.get(1);

		//not enough units available to assign em2
		facade.assignAllUnits(gonnaBeAssigned);
	}
}
